package http;

import model.ApiConfigDataModel;
import model.ApiDataModel;
import tool.DataReplace;

import java.net.HttpURLConnection;
import java.util.Map;

/**
 * Created by yangxianming on 2015-06-10.
 */
public class Header implements HeaderImpl {
    ApiDataModel adm = null;
    ApiConfigDataModel acdm = null;

    Header(ApiDataModel adm, ApiConfigDataModel acdm){
        this.adm = adm;
        this.acdm = acdm;
    }

    @Override
    public void setHeader(HttpURLConnection conn) {
        for (Map.Entry<String, String> me:adm.header.entrySet()){
            String k = me.getKey();
            String v = me.getValue();
            v = DataReplace.replace(acdm, v);
            conn.setRequestProperty(k, v);
            me.setValue(v);     //放回替换后的数据
        }
    }
}
